home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / protect-your-privacy / p.g.p. / pgpamiga / contrib / ced / dopgp.ced < prev    next >
Text File  |  1996-02-26  |  7KB  |  204 lines

  1. /*
  2.  * doPGP.ced
  3.  *
  4.  * $VER: Rick Younie 27 July 1994 Wednesday
  5.  *
  6.  *    please send comments, questions or improvements:
  7.  *              rick@emma.panam.wimsey.com
  8.  *              rick@freenet.vancouver.bc.ca (faster)
  9.  *
  10.  * SYNOPSIS:
  11.  *              {de/en}crypt the mail message in CED with PGP
  12.  *                      - bring up a requester to choose the recipient's public key
  13.  *                      - add my public key at the end of the message
  14.  *
  15. DOCS
  16. ----
  17. This script interfaces PGP and Cygnus Ed.  I use it with AmigaElm to
  18. encrypt and decrypt PGP messages.  Make sure it is in your REXX:
  19. directory and the script bit is set.
  20.  
  21. Note:  be sure to set the following variables under the 'constants
  22.         and assigns' heading.
  23.  
  24.         keyFile - the name of your key in ascii format.  This is appended
  25.                           to outgoing messages.
  26.         pgp     - the path and name of the PGP binary
  27.  
  28.  
  29. decrypt
  30.         - send 'doPGP -d' with Cygnus Ed's Send Dos/ARexx command menu
  31.         item.  The first paragraph in CED is assumed to be the message
  32.         header and is skipped.  The rest of the message is cut to a temp
  33.         file and passed to PGP.  PGP does its magic and the result is
  34.         pasted back into CED.  If there is a key appended to the message,
  35.         you are asked if you want to add it to your key file.
  36.  
  37. encrypt
  38.         - send 'doPGP -e'.  The CED view must start with 'To: ' and the
  39.         first paragraph is assumed to be the outgoing message header and
  40.         is skipped.  The body of the message is cut to a temp file and
  41.         passed to PGP to encrypt, then pasted back.  Your key file is
  42.         added to the end of the message.
  43.  */
  44.  
  45.    signal on NOVALUE
  46.    signal on SYNTAX
  47.    signal on BREAK_C
  48.    signal on HALT
  49.  
  50. /*      -------------------------------------------------------------------
  51.  *   constants and assigns
  52.  */
  53.  
  54.         lf                      = '0a'x
  55.         tmpFile         = 't:'pragma('ID')'doPGP'               /* make a unique name */
  56.  
  57.         pgp                     = 'uucp:bin/pgp'         /* path & filename of PGP binary */
  58.         keyFile         = 'PGP:keys/rick.asc'                            /* my public key */
  59.  
  60. /*      -------------------------------------------------------------------
  61.  */
  62. Main:
  63.         address 'rexx_ced'
  64.         options Results
  65.  
  66.         /* parse input */
  67.         select
  68.                 when arg(1) = '-e' then call Encrypt
  69.                 when arg(1) = '-d' then call Decrypt
  70.                 otherwise call Usage
  71.         end
  72.         exit
  73.  
  74. /*      -------------------------------------------------------------------
  75.  *
  76.  */
  77. Decrypt:
  78.         call NewSTD                                                       /* reassign stdin, stdout */
  79.         call BodyToTmp                           /* cut the message body and save it*/
  80.         address 'COMMAND' pgp tmpFile '-o'tmpFile'.dec'   /* decrypt it */
  81.         'include file' tmpFile'.dec'           /* load it back into CED */
  82.         address 'COMMAND' 'delete' tmpfile'*'                            /* cleanup */
  83.         return
  84.  
  85.  
  86. /*      -------------------------------------------------------------------
  87.  *
  88.  */
  89. Encrypt:
  90.         call IsMsg                                                              /* really mail message? */
  91.         call NewSTD                                                       /* reassign stdin, stdout */
  92.         recip = CheckRecip()             /* selected the right persons key? */
  93.         call BodyToTmp                           /* cut the message body and save it*/
  94.         address 'COMMAND' pgp '-ea' tmpFile recip  /* encrypt that body */
  95.         'include file' tmpFile'.asc'               /* load it back into CED */
  96.         address 'COMMAND' 'delete' tmpFile'*'                            /* cleanup */
  97.         call AppendKey                                                                    /* add my key */
  98.         return
  99.  
  100. /*      -------------------------------------------------------------------
  101.  *      append my key to encrypted message
  102.  */
  103. AppendKey:
  104.         'end of file'
  105.         'return'
  106.         'include file' keyFile
  107.         return
  108.  
  109. /*      -------------------------------------------------------------------
  110.  *      cut the message body to temp file
  111.  */
  112. BodyToTmp:
  113.         'beg of file'
  114.         'search for' '"'lf || lf'"'
  115.         'beg of line'
  116.         'down'
  117.         'down'
  118.         'mark block'
  119.         'end of file'
  120.         'cut block'
  121.         'save block to file' tmpFile 1
  122.         return
  123.  
  124.  
  125. /*      -------------------------------------------------------------------
  126.  *      open a window on CED for pgp output/input
  127.  */
  128. NewSTD:
  129.         call close 'STDOUT'
  130.         call close 'STDIN'
  131.         call open 'STDOUT', 'CON:10/120/630/100/CED/SCREEN CygnusEdScreen1'
  132.         call pragma '*','STDOUT'
  133.         call open 'STDIN','*'
  134.         return
  135.  
  136.  
  137. /*      -------------------------------------------------------------------
  138.  *      make sure the recipient exists in keyfile and is the right one
  139.  */
  140. CheckRecip: PROCEDURE EXPOSE pgp
  141.  
  142.         do forever
  143.                 options prompt "Enter recipient's name: "
  144.                 parse pull recip
  145.  
  146.                 address 'COMMAND' pgp '-kv' recip
  147.  
  148.                 /* error return from pgp - couldn''t find key for this guy */
  149.                 if RC > 0 then do
  150.                         say '..couldn''t find "'recip'" in keyfile.'
  151.                         options prompt "Try another? Y/q "
  152.                         pull ans
  153.                         if ans = 'Q' then call ErX '..user aborted'
  154.                 end
  155.  
  156.                 /* found a key - the right one? */
  157.                 else do
  158.                         options prompt "Is this the right guy? Y/n/q "
  159.                         pull ans
  160.                         select
  161.                                 when ans = 'Y' | ans = '' then leave
  162.                                 when ans = 'Q' then call ErX '..user aborted'
  163.                                 otherwise nop
  164.                         end /* select */
  165.                 end /* else */
  166.  
  167.         end /* forever */
  168.  
  169.         return recip
  170.  
  171. /*      -------------------------------------------------------------------
  172.  *      only attempt encrypt if 1st line begins with 'To:'
  173.  */
  174. IsMsg:
  175.         /* check that first word is 'To:' */
  176.         'beg of file'
  177.         'status 55'
  178.         if ~abbrev(result,'To:') then
  179.                 call ErX '..file in CED must start with To:'
  180.         return
  181.  
  182. /* ----------------------------------------------------------------------
  183.  */
  184. ErX:
  185.         'okay1' arg(1)
  186.         exit
  187.  
  188. /* ----------------------------------------------------------------------
  189.  * minimal traps
  190.  */
  191. NOVALUE: errtype = 'NOVALUE'
  192. SYNTAX:  if symbol('errtype') = 'LIT' then errtype = 'SYNTAX'
  193.         call ErX errtype 'error in doPGP; maybe line' SIGL'; maybe RC' RC
  194. HALT:
  195. BREAK_C:
  196.         exit
  197.  
  198. /*      -------------------------------------------------------------------
  199.  *  in case program is invoked from cli
  200.  */
  201. Usage:
  202.         say 'Usage: dopgp [-e | -d]  - encrypt | decrypt - use only in CED'
  203.         exit
  204.